package com.wyl.wyl.testapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wyl.wyl.testapplication.R;
import com.wyl.wyl.testapplication.bean.PersonMainBean;

import java.util.List;

/**
 * Created by es on 2019/4/28.
 */

public class LineingAdapter extends BaseAdapter {
    private Context context;
    private List<PersonMainBean.BodyBean.LineingBean> list;

    public LineingAdapter(Context context, List<PersonMainBean.BodyBean.LineingBean> list) {
        this.context = context;
        this.list = list;
    }
    public void notifyData (List<PersonMainBean.BodyBean.LineingBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LineingAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.car_item, null);
            holder = new LineingAdapter.ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (LineingAdapter.ViewHolder) convertView.getTag();
        }
        PersonMainBean.BodyBean.LineingBean materialBean = list.get(position); // 获取当前项的CarBean实例

        holder.car.setText(materialBean.getOrder_line());
        holder.carNumber.setText(materialBean.getDelivery_vehicle_name());
        holder.schedule.setText(materialBean.getIs_sign());
        holder.storeId.setText(materialBean.getDelivery_driver_name());

        return convertView;
    }

    private class ViewHolder {
        private TextView car;
        private TextView carNumber;
        private TextView schedule;
        private TextView storeId;

        public ViewHolder(View view) {
            car = (TextView) view.findViewById(R.id.car_id);//获取该布局内的文本视图
            carNumber = (TextView) view.findViewById(R.id.car_number);
            schedule = (TextView) view.findViewById(R.id.schedule);
            storeId = (TextView) view.findViewById(R.id.store_number);
        }
    }

}
